package com.z.service;

import com.z.base.LoginUser;
import com.z.dao.AccountDao;
import com.z.entity.Account;
import com.z.util.MD5;
import com.z.vo.AuthenticationForm;

public class AuthenticationService {
	private static AuthenticationService authenticationService;
	
	public static AuthenticationService getInstance(){
		if(authenticationService==null){
			authenticationService=new AuthenticationService();
		}
		return authenticationService;
	}
	/**
	 * 检查帐号、密码是否正确
	 * @param form VO
	 * @return
	 */
	public LoginUser findByPassword(AuthenticationForm form) {
		try{
			Account account = AccountDao.getInstace().findByPassword(form.getAccount(),MD5.makeMD5(form.getPassword()));
			
			LoginUser loginUser=new LoginUser();
			loginUser.setManager(account.isManager());
			loginUser.setUsrId(account.getId());
			loginUser.setUsrName(account.getName());
			return loginUser;
		}catch(Exception e){
			return null;
		}
	}
}
